<?php

class newprinter_finder_delivery extends ome_finder_delivery {

    var $addon_cols = "skuNum,itemNum,bnsContent,delivery_id,status,process,stock_status,deliv_status,expre_status,verify,is_bind,type,bind_key,order_createtime";

    //显示状态
    var $column_process = "发货单状态";
    var $column_process_width = "80";
    function  column_process($row) {

        $stock = $row[$this->col_prefix.'stock_status'];
        $deliv = $row[$this->col_prefix.'deliv_status'];
        $expre = $row[$this->col_prefix.'expre_status'];
        $proc  = $row[$this->col_prefix.'process'];
        $verify= $row[$this->col_prefix.'verify'];
        if ($stock=='false' && $deliv=='false' && $expre=='false'){
            return '未打印';
        }
        if ($stock=='true' && $deliv=='true' && $expre=='true'){
            if ($proc=='true'){
                return '已发货';
            }
            if ($verify=='true'){
                return '已校验待发货';
            }
            return '已打印待备货';
        }else {
            return '正在打印';
        }
    }

    //显示状态
    var $column_status = "打印状态";
    var $column_status_width = "80";

    function column_status($row) {

        $stock = $row[$this->col_prefix . 'stock_status'];
        $stockColor = ($stock == 'true') ? 'green' : '#eeeeee';
        $deliv = $row[$this->col_prefix . 'deliv_status'];
        $delivColor = ($deliv == 'true') ? 'red' : '#eeeeee';
        $expre = $row[$this->col_prefix . 'expre_status'];
        $expreColor = ($expre == 'true') ? 'gold' : '#eeeeee';
        $ret = $this->getViewPanel('备货单', $stockColor);
        $ret .= $this->getViewPanel('发货单', $delivColor);
        $ret .= $this->getViewPanel('快递单', $expreColor);
        return $ret;
    }

    public function getViewPanel($caption, $color) {
        if ($color == '#eeeeee')
            $caption .= '未打印';
        else
            $caption .= '已打印';
        return sprintf("<div style='width:18px;padding:2px;height:16px;background-color:%s;float:left;'><span alt='%s' title='%s'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div>",
                $color, $caption, $caption);
    }

    //显示状态
    var $column_create = "下单到现在";
    var $column_create_width = "100";

    function column_create($row) {

        $time = $row[$this->col_prefix . 'order_createtime'];
        $status = $row[$this->col_prefix . 'status'];
        $now = time();
        $beforeNow = $now - $time;
        $beforeNow = $beforeNow >0 ?$beforeNow : 0;
        $days = intval($beforeNow / 86400);
        if ($status == 'progress' || $status == 'ready') {
            if ($days >= 7) {
                $ret = "<div style='width:90px;height:20px;background-color:red;color:#FFFFFF;text-align:center;'>超过一周</div>";
            } elseif ($days >= 1) {
                $ret = "<div style='width:90px;height:20px;background-color:blue;color:#FFFFFF;text-align:center;'>" . $this->_genDayStr($beforeNow) . "</div>";
            } else {
                $ret = "<div style='width:90px;height:20px;background-color:green;color:#FFFFFF;text-align:center;'>" . $this->_genDayStr($beforeNow) . "</div>";
            }
        } else {
            $ret = "<div style='width:90px;height:20px;background-color:#dddddd;color:#FFFFFF;text-align:center;'>完成</div>";
        }
        return $ret;
    }

    function _genDayStr($time) {

        $d = intval($time / 86400);
        $ret = ($d >0) ? "{$d}天" : "";
        $h = intval(($time - $d*86400) / 3600);
        $ret .= "{$h}小时";
        $m = intval(($time - $d*86400 - $h*3600) / 60);
        $ret .= "{$m}分";

        return $ret;
    }

    //显示状态
    var $column_content = "订单内容";
    var $column_content_width = "160";
    var $column_content_orderas = "idx_split";

    function column_content($row) {

        $skuNum = $row[$this->col_prefix . 'skuNum'];
        $itemNum = $row[$this->col_prefix . 'itemNum'];
        $content = $row[$this->col_prefix . 'bnsContent'];

        $cnts = unserialize($content);
        $cnt = sprintf("共有 %d 种商品，总共数量为 %d 件， 具体 SKU 为： %s", $skuNum, $itemNum, @implode(', ', $cnts));

        @reset($cnts);
        $content = $cnts[@key($cnts)];
        if ($skuNum >1) {

            $content .= ' 等';
        }

        return sprintf("<span alt='%s' title='%s'><font color='red'>(<b>%d</b> / <b>%d</b>)</font> %s</span>",$cnt, $cnt, $skuNum, $itemNum, $content);
    }
}

?>